import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

import i18n from '@/lang'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/homepage',
    children: [
      {
        path: 'homepage',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'BookStore2["Menu:Dashboard"]', icon: 'el-icon-s-home', affix: true }
      }
    ]
  }
  // {
  //   path: '/documentation',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/documentation/index'),
  //       name: 'Documentation',
  //       meta: { title: 'BookStore2["Menu:Documentation"]', icon: 'documentation', affix: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/guide',
  //   component: Layout,
  //   redirect: '/guide/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/guide/index'),
  //       name: 'Guide',
  //       meta: { title: 'BookStore2["Menu:Guide"]', icon: 'guide', noCache: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/profile',
  //   component: Layout,
  //   redirect: '/profile/index',
  //   hidden: true,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/profile/index'),
  //       name: 'Profile',
  //       meta: { title: 'BookStore2["Menu:Profile"]', icon: 'user', noCache: true }
  //     }
  //   ]
  // }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
// export const asyncRoutes = [
//   /** when your routing map is too long, you can split it into small modules **/
//   identityRouter,
//   tenantRouter,
//   dictionaryRouter,
//   auditlogRouter,
//   settingRouter,
//   // 404 page must be placed at the end !!!
//   { path: '*', redirect: '/404', hidden: true }
// ]

export const asyncRoutes = [
  {
    path: '/administration',
    // component: { render: c => c('router-view') },
    component: Layout,
    name: 'Administration',
    meta: { title: i18n.t('BookStore2[\'Administration\']'), icon: 'el-icon-setting' },
    children: [
      // {
      //   path: 'saas',
      //   component: Layout,
      //   name: 'saas',
      //   meta: { title: 'Sass' },
      //   children: [{
      //     path: 'tenants',
      //     name: 'tenant',
      //     meta: { title: '租户', policy: 'AbpTenantManagement.Tenants' },
      //     component: () => import('@/views/administration/saas/tenants/tenant')
      //   },
      //   {
      //     path: 'editions',
      //     name: 'edition',
      //     meta: { title: '版本' },
      //     component: () => import('@/views/administration/saas/editions/edition')
      //   }]
      // },
      // {
      //   path: 'identity',
      //   component: Layout,
      //   name: 'identityManagement',
      //   meta: { title: i18n.t('BookStore2[\'IdentityManagement\']') },
      //   children: [
      {
        path: 'organization/index',
        name: 'OrganizationUnit',
        meta: { title: i18n.t('BookStore2[\'OrganizationUnit\']'), icon: 'el-icon-office-building', policy: 'AbpIdentity.OrganizationUnits' },
        component: () => import('@/views/administration/identity/organizationUnit/organizationUnit')
      },
      {
        path: 'role/index',
        name: 'Role',
        meta: { title: i18n.t('BookStore2[\'Role\']'), icon: 'el-icon-set-up', policy: 'AbpIdentity.Roles' },
        component: () => import('@/views/administration/identity/role/role')
      }
      // {
      //   path: 'claim-types',
      //   name: 'claimType',
      //   meta: { title: '声明类型', policy: 'AbpIdentity.ClaimTypes' },
      //   component: () => import('@/views/administration/identity/claimType/claimType')
      // }
      // {
      //   path: 'security-logs',
      //   name: 'securityLog',
      //   meta: { title: '安全日志' },
      //   component:
      // }
      // ]
      // }
      // {
      //   path: 'language-management',
      //   component: Layout,
      //   name: 'languageManagement',
      //   meta: { title: '语言管理' },
      //   children: [{
      //     path: 'languages',
      //     name: 'languages',
      //     meta: { title: '语言' },
      //     component: () => import('@/views/administration/languageManagement/language/language')
      //   },
      //   {
      //     path: 'texts',
      //     name: 'texts',
      //     meta: { title: '语言文本' },
      //     component: () => import('@/views/administration/languageManagement/texts/texts')
      //   }]
      // },
      // {
      //   path: '',
      //   component: Layout,
      //   name: '',
      //   meta: { title: '' },
      //   children: [{
      //     path: 'audit-logs',
      //     name: 'auditLog',
      //     meta: { title: '审计日志', policy: 'AbpAuditLogging.Default' },
      //     component: () => import('@/views/administration/auditLog/auditLog')
      //   }]
      // }
    ]
  },
  {
    // 用户管理
    path: '/user',
    component: Layout,
    children: [{
      path: 'index',
      name: 'User',
      meta: { title: i18n.t('BookStore2[\'Staff\']'), icon: 'el-icon-user', policy: 'AbpIdentity.Users' },
      component: () => import('@/views/administration/identity/user/user')
    }]
  },
  {
    // 车辆调度
    path: '/queue',
    component: Layout,
    children: [{
      path: 'index',
      name: 'TrafficDispatchTask',
      meta: { title: i18n.t('BookStore2[\'TrafficDispatchTask\']'), icon: 'el-icon-s-platform', policy: 'BookStore2TrafficDispatchTask' },
      component: () => import('@/views/trafficDispatch/trafficDispatchTask')
    }, {
      path: 'task/:trafficDispatchTaskId',
      name: 'TrafficDispatchTaskItem',
      meta: { title: i18n.t('BookStore2[\'TrafficDispatchTaskItem\']'), policy: 'BookStore2TrafficDispatchTask' },
      component: () => import('@/views/trafficDispatch/trafficDispatchTaskItem'),
      props: true,
      hidden: true
    }]
  },
  {
    // 车辆管理
    path: '/vehicle',
    component: Layout,
    meta: { title: i18n.t('BookStore2[\'VehicleMgr\']'), icon: 'el-icon-truck' },
    children: [{
      path: 'index',
      name: 'Vehicle',
      meta: { title: i18n.t('BookStore2[\'VehicleMgr\']'), icon: 'el-icon-truck', policy: 'BookStore2Vehicle' },
      component: () => import('@/views/vehicle/vehicle')
    }, {
      path: 'index2',
      name: 'Vehicle2',
      meta: { title: i18n.t('BookStore2[\'VehicleMgr\']'), icon: 'el-icon-truck', policy: 'BookStore2Vehicle' },
      component: () => import('@/views/vehicle/vehicle2')
    }, {
      path: 'inspection/:vehicleId',
      name: 'VehicleInspection',
      meta: { title: i18n.t('BookStore2[\'VehicleInspectionRecord\']') },
      component: () => import('@/views/vehicle/inspectionRecord'),
      props: true,
      hidden: true
    }, {
      path: 'drive/:vehicleId',
      name: 'VehicleDrive',
      meta: { title: i18n.t('BookStore2[\'VehicleDriveRecord\']') },
      component: () => import('@/views/vehicle/driveRecord'),
      props: true,
      hidden: true
    }, {
      path: 'maintenance/:vehicleId',
      name: 'VehicleMaintenance',
      meta: { title: i18n.t('BookStore2[\'VehicleMaintenanceRecord\']') },
      component: () => import('@/views/vehicle/maintenanceRecord'),
      props: true,
      hidden: true
    }, {
      path: 'repair/:vehicleId',
      name: 'VehicleRepair',
      meta: { title: i18n.t('BookStore2[\'VehicleRepairRecord\']') },
      component: () => import('@/views/vehicle/repairRecord'),
      props: true,
      hidden: true
    }]
  },
  {
    // 排班表
    path: '/schedule',
    component: Layout,
    meta: { title: i18n.t('BookStore2[\'WorkSchedule\']'), icon: 'el-icon-date' },
    children: [{
      path: 'index',
      name: 'WorkSchedule',
      meta: { title: i18n.t('BookStore2[\'WorkSchedule\']'), icon: 'el-icon-date', policy: 'BookStore2WorkSchedule' },
      component: () => import('@/views/workSchedule/workSchedule')
    }, {
      path: 'items/:workScheduleId',
      name: 'WorkScheduleItem',
      meta: { title: i18n.t('BookStore2[\'WorkScheduleItem\']') },
      component: () => import('@/views/workSchedule/workScheduleItem'),
      props: true,
      hidden: true
    }, {
      path: 'index2',
      name: 'WorkSchedule2',
      meta: { title: i18n.t('BookStore2[\'WorkSchedule\']'), icon: 'el-icon-date', policy: 'BookStore2WorkSchedule' },
      component: () => import('@/views/workSchedule/workSchedule2')
    }]
  },
  {
    // 公告
    path: '/board',
    component: Layout,
    children: [{
      path: 'index',
      name: 'Board',
      meta: { title: i18n.t('BookStore2[\'NoticeMgr\']'), icon: 'el-icon-message', policy: 'BookStore2Notice' },
      component: () => import('@/views/notice/notice')
    }]
  },
  {
    // 物资请求
    path: '/request',
    component: Layout,
    children: [{
      path: 'index',
      name: 'Todo',
      meta: { title: i18n.t('BookStore2[\'TodoMgr\']'), icon: 'el-icon-s-claim', policy: 'BookStore2Todo' },
      component: () => import('@/views/todo/todo')
    }]
  },
  {
    // 请假管理
    path: '/vacation',
    component: Layout,
    children: [{
      path: 'index',
      name: 'Vacation',
      meta: { title: i18n.t('BookStore2[\'VacationMgr\']'), icon: 'el-icon-s-claim', policy: 'BookStore2Vacation' },
      component: () => import('@/views/vacation/vacation')
    }]
  },
  {
    path: '/tmp',
    component: Layout,
    children: [{
      path: 'index',
      name: 'MessageTemplate',
      meta: { title: i18n.t('BookStore2[\'MessageTemplate\']'), icon: 'el-icon-document-copy', policy: 'BookStore2MessageTemplate' },
      component: () => import('@/views/messageTemplate/messageTemplate')
    }]
  },
  {
    path: '/qa',
    component: Layout,
    children: [{
      path: 'index',
      name: 'QuestionAndAnswer',
      meta: { title: i18n.t('BookStore2[\'QuestionAndAnswer\']'), icon: 'el-icon-question', policy: 'BookStore2QuestionAndAnswerPost' },
      component: () => import('@/views/questionAndAnswer/questionAndAnswerPost')
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
